using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;

public enum AniType {
    None,
    Idle,
    Walk
}

public enum AniDir
{
    None,
    Up,
    Left,
    Down,
    Right
}

public class ItemDef
{
    public const int TypeIdWater = 1;
    public const int TypeIdBrick = 2;

    public static int GetTypeId(string prefabName)
    {
        foreach (var item in ConfigItem.id2Element.Values)
        {
            if (item.PrefabName == prefabName)
                return item.Id;
        }
        Debug.LogError("Can not find prefabName:" + prefabName);
        return -1;
    }

}

public enum TaskType
{
    Item
}

public class MapMix
{
    public const float DefaultZ = 0;
    public const int DefaultZInt = 0;
    public const float GridXL = 1;
    public const float GridYL = 1;
    public const float XL = 100;
    public const float YL = 100;

    static int gridX;
    static int gridY;
    public static int GetIndex(Vector3 pos)
    {
        GetGrid(pos, out gridX, out gridY);
        return GetIndex(gridX, gridY);
    }

    public static int GetIndex(int gridX, int gridY)
    {
        return (int)GridYL * gridX + gridY;
    }

    public static Vector3 GetPos(int gridX, int gridY)
    {
        return new Vector3(gridX, gridY, DefaultZ);
    }

    public static void GetGrid(Vector3 pos, out int gridX, out int gridY)
    {
        gridX = Mathf.RoundToInt(pos.x);
        gridY = Mathf.RoundToInt(pos.y);
    }

    //是否障碍物
    public static bool IsBarrier(string gridName)
    {
        var match = Regex.Match(gridName, "Wall|Gate Close|Stone");
        return match.Success;
    }
}